<%@ page import="java.util.ArrayList" %>
<%@ page import="vo.Student" %>
<%@ page import="vo.Teacher" %>
<%@ page import="java.io.File" %>
<%--需要两个jar包jstl、standard--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="../resources/css/bootstrap.min.css">
    <link rel="stylesheet" href="../resources/css/jquery-ui-1.10.4.custom.min.css">
    <script src="../resources/js/jquery-1.10.2.js"></script>
    <script src="../resources/js/jquery-ui-1.10.4.custom.min.js"></script>
    <title>学生信息管理</title>
    <link href="../resources/css/default.css" rel="stylesheet"/>
</head>
<body>
<%@include file="../Util.jsp"%>
<%
    Teacher teacher = (Teacher) session.getAttribute("info");
    ArrayList<Student> stus = (ArrayList<Student>) session.getAttribute("onePageStudent");
    int sumIndex = (int) session.getAttribute("sumIndex");
    int currentIndex = (int) session.getAttribute("currentIndex");
    String imgPath = "default";
    try {
        String path = "D:\\code\\2024\\Project\\StuddentManager\\web\\userImg";
        String name = teacher.getId() + ".jpg";
        File imgFile = new File(path,name);
//        System.out.println(imgFile.exists());
        if (imgFile.exists()) {
            imgPath = teacher.getId();
        }
//        System.out.println(imgPath);
    } catch (Exception e) {
        out.print(e);
    }
%>
<div id="page" class="mycontainer">
    <div id="header">
        <div id="logo">
            <img src="../userImg/<%=imgPath%>.jpg"/>
            <h1><%=teacher.getId()%></h1>
        </div>
        <div id="menu">
            <ul>
                <li><a href="personal.jsp">个人信息</a></li>
                <li class="current_page_item"><a href="../one_page_student">学生管理</a></li>
                <li><a href="../one_page_score">成绩管理</a></li>
                <li><a href="../exit" onclick="return confirm('确认退出?');">退出登录</a></li>
            </ul>
        </div>
    </div>
    <div id="main">
        <div class="top">
            <h2>学生信息管理</h2>
            <hr/>
            <button class="btn btn-success btn-add">添加学生</button>
            <div class="find">
                <form action="../one_page_student" method="post">
                    <input id="find-text" type="text" name="key" placeholder="输入学号或姓名搜索">
                    <input class="find-btn" type="submit" value="搜索">
                </form>
            </div>
        </div>
        <div class="table" style="height: 600px ">
            <table id="table" width="700" frame="box" align="center">
                <tr>
                    <th height="35">学号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>入学日期</th>
                    <th>专业</th>
                    <th>操作</th>
                </tr>
                <%
                    for (Student stu : stus) {
                        if(stu!=null){
                            request.setAttribute("sex",stu.getSex()); //设置域对象
                %>
                            <tr>
                                <form method="post" action="../update_student">
                                    <td height="35"><%=stu.getId()%></td>
                                    <td><input value="<%=stu.getName()%>" name="stuname" class="table-input"></td>
                                    <td>
                                        <div class="form-check form-check-inline">
                                            <input name="stusex" id="by" type="radio" value="男" <c:if test="${sex=='男'}">checked</c:if> class="form-check-input">
                                            <label class="form-check-label" for="by">男</label>
                                        </div>
                                        <div class="form-check form-check-inline">
                                            <input name="stusex" id="gl" type="radio" value="女" <c:if test="${sex=='女'}">checked</c:if> class="form-check-input">
                                            <label class="form-check-label" for="gl">女</label>
                                        </div>
                                    </td>
                                    <td><%=stu.getSchool_date()%></td>
                                    <td><input value="<%=stu.getMajor()%>" name="stumajor" class="table-input" style="width: 125px"></td>
                                        <input value="<%=stu.getId()%>" name="stuno" type="hidden">
                                    <td>
                                        <input type="submit" class="update-btn" value="修改">&nbsp;
                                        <a href=<%="'../delete_student?id=" + stu.getId() + "'"%> class="btn-delete" onclick="return confirm('确定要删除吗?');">删除</a>&nbsp;&nbsp;
                                        <a href="../one_page_score?id=<%=stu.getId()%>">查看成绩</a>
                                    </td>
                                </form>
                            </tr>
                <%
                        }
                    }
                %>
            </table>
        </div>
        <div id="index">
            <a href="../one_page_student?index=1">首页</a>
            <a href="../one_page_student?index=<%=(currentIndex-1<1?1:currentIndex-1)%>">上一页</a>
            <a href="../one_page_student?index=<%=(currentIndex+1>sumIndex?sumIndex:currentIndex+1)%>">下一页</a>
            <a href="../one_page_student?index=<%=sumIndex%>">尾页</a>
        </div>
    </div>
</div>

<%--添加学生信息对话框--%>
<div id="add-dialog" title="添加学生信息">
    <form id="add-form" method="post" class="form-group">
        学号:<input name="id" type="text" class="form-control"><br>
        姓名:<input name="name" type="text" class="form-control"><br>
        性别:
        <div class="form-check form-check-inline">
            <input name="sex" id="boy" type="radio" value="男" checked class="form-check-input">
            <label class="form-check-label" for="boy">男</label>
        </div>
        <div class="form-check form-check-inline">
            <input name="sex" id="girl" type="radio" value="女" class="form-check-input">
            <label class="form-check-label" for="girl">女</label>
        </div> <br><br>
<%--        性别:<input name="sex" type="text" class="form-control"><br>--%>
        专业:<input name="major" type="text" class="form-control"><br>
        入学日期:<input name="school_date" type="month" class="form-control">
        <hr>
        <input style="float: right" type="submit" value="取消" class="btn btn-info" onclick="function x() {
          $('#add-dialog').dialog('close');
        }">
        <input style="float: right; margin-right: 25px" type="submit" value="确定" class="btn btn-success"
               onclick="this.form.action='../add_student'">
    </form>
</div>

<script>
    // 初始化对话框
    $('#add-dialog').dialog({
        // 宽度310像素
        width: 310,
        // 默认不自动打开
        autoOpen: false,
        // 不可移动
        draggable: false,
        // 模态、打开窗口后无法操作其他窗口
        modal: true,
        // 不可改变窗口大小
        resizable: false
    });
    // 绑定点击事件
    $('.btn-add').click(function () {
        $('#add-dialog').dialog('open');
    });
</script>
</body>
</html>

